package com.ee.chat.admin.controller.materialmanage;

import com.ee.chat.admin.service.IPushService;
import com.ee.chat.common.bean.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author Shane
 * @Date 2020/3/13 14:40
 */
@RestController
@RequestMapping("push")
public class PushController {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Resource
    IPushService pushService;

    @RequestMapping("list")
    public Result list(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer limit, String keyword){
        try {
            return pushService.list(request, page, limit, keyword);
        } catch (Exception e){
            log.error("【获取推送信息列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 添加
     * @Author Shane
     * @Date 2020/3/13 23:04
     * @param msgType  消息类型，0-公告消息  1-个人消息
     * @param userId    解析接收者
     * @param title     消息标题
     * @param content   消息内容
     * @return
     */
    @RequestMapping("add")
    public Result add(HttpServletRequest request, @RequestParam Integer msgType, @RequestParam(required = false) Integer userId, @RequestParam String title, @RequestParam String content){
        try {
            return pushService.add(request, msgType, userId, title, content);
        } catch (Exception e){
            log.error("【添加推送信息错误】", e);
        }
        return Result.returnFailure();
    }
}
